(function($) {
	$(window).load(function(e) {
		$("#da-ex-tabs, #da-ex-tabs-plain").tabs();
		
		$("#da-ex-calendar-gcal").fullCalendar({
			events: 'http://www.google.com/calendar/feeds/usa__en%40holiday.calendar.google.com/public/basic',
				
			eventClick: function(event) {
				// opens events in a popup window
				window.open(event.url, 'gcalevent', 'width=700,height=600');
				return false;
			}
		});
		
		var url = "modul/beranda/get_perkara_count.php";
		$.post(url, {} ,function(data) {
			var obj = eval ("(" + data + ")");
			var pb = new Array();
			var perkaraBaru = new Array();
			var startDate;
			var endDate;
			for(var i=0; i<obj.perkaras.length;i++){
				pb[i]=obj.perkaras[i].total;
				perkaraBaru.push([new Date(Date.UTC(obj.perkaras[i].tahun, obj.perkaras[i].bulan-1, obj.perkaras[i].hari)), pb[i]]);
				if(i==0){
					startDate = new Date(Date.UTC(obj.perkaras[i].tahun, obj.perkaras[i].bulan-1, obj.perkaras[i].hari));
				}
				
				if(i==obj.perkaras.length-1){
					endDate = new Date(Date.UTC(obj.perkaras[i].tahun, obj.perkaras[i].bulan-1, obj.perkaras[i].hari));
				}
			}

			if( $.plot ) {
			
				var previousPoint = null;
							
				var opts = {
					series: {
						lines: { show: true }, 
						points: { show: true }
					}, 
					tooltip: true, 
					tooltipOpts: {
						content: "%y",
						defaultTheme: false
					}, 
					xaxis: {
						mode: "time", 
						min: startDate.getTime(),
						max: endDate.getTime()
					}, 
					grid: { 
						hoverable: true, 
						clickable: true, 
						borderWidth: null
					}
				};
				
				var plot = $.plot($("#da-ex-flot"), 
					[
					 { data: perkaraBaru, label: "Perkara Baru", color: "#fab241"}				], 
					opts
				);
			}
			
		});
		

	});
}) (jQuery);
